<?php 
  
//获取微信操作对象
function & load_wechat($type = '') {
    !class_exists('Wechat\Loader', FALSE) && Vendor('Wechat.Wechat.Loader'); 
    static $wechat = array();
    $index = md5(strtolower($type));
    if (!isset($wechat[$index])) {
        // 从数据库查询配置参数
        $config = M('config',"wechat_")->field('token,appid,appsecret,encodingaeskey,mch_id,partnerkey,ssl_cer,ssl_key,qrc_img')->find();
        // 设置SDK的缓存路径
        $config['cachepath'] = CACHE_PATH . 'Data/';
        $wechat[$index] = \wechat\Loader::get_instance($type, $config);
    }
    return $wechat[$index];
}

function is_HTTPS()
		{
		    if (!isset($_SERVER['HTTPS'])) return FALSE;
		    if ($_SERVER['HTTPS'] === 1) {  //Apache
		        return TRUE;
		    } elseif ($_SERVER['HTTPS'] === 'on') { //IIS
		        return TRUE;
		    } elseif ($_SERVER['SERVER_PORT'] == 443) { //其他
		        return TRUE;
		    }
		    return FALSE;
		}

function getDomain()
		{
		    $server_name = $_SERVER['SERVER_NAME'];

		    if (strpos($server_name, 'www.') !== false) {
		        return substr($server_name, 4);
		    }

		    return $server_name;
		}